<template>
  <!-- 添加或修改匿名投诉对话框 -->
  <el-dialog :close-on-click-modal="false" :title="formType" :visible.sync="open" @close="cancel"
             width="500px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="举报原因" prop="id">
            <el-input v-model="form.id" placeholder="请输入举报原因"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="用户" prop="userId">
            <el-input v-model="form.userId" placeholder="请输入用户"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="投诉用户" prop="toUserId">
            <el-input v-model="form.toUserId" placeholder="请输入投诉用户"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="举报原因" prop="reportReason">
            <el-select v-model="form.reportReason" placeholder="请选择举报原因">
              <el-option
                v-for="dict in reportReasonOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="图片集合" prop="explainImg">
            <el-input v-model="form.explainImg" placeholder="请输入图片集合"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="补充描述" prop="describe">
            <el-input v-model="form.describe" placeholder="请输入补充描述"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="补充描述" prop="lastupdateTime">
            <el-date-picker clearable size="small" style="width: 200px"
                            v-model="form.lastupdateTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择补充描述">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import operationModule from '@/mixins/operation-module'
  import {
    addReport,
    updateReport
  } from '@/api/complain/report'

  export default {
    name: 'add-or-update',
    mixins: [operationModule],
    data() {
      return {
        // 设置属性
        mixinOperationModuleOptions: {
          saveURL: addReport, // 提交数据接口，api地址
          updateURL: updateReport // 提交数据接口，api地址
        },
        moduleName: 'Report',
        open: false,
        // 弹出层标题
        //表单操作类型
        formType: this.$formType.add,
        // 表单参数
        form: {},
        // 举报原因字典
        reportReasonOptions: [],
        // 表单校验
        rules: {}
      }
    },
    methods: {
      init(type) {
        this.reset()
        this.open = true
        if (type == this.$formType.add) {
        } else if (type == this.$formType.edit) {
        } else if (type == this.$formType.detail) {
        }
        this.formType = type
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          userId: undefined,
          toUserId: undefined,
          reportReason: undefined,
          explainImg: undefined,
          describe: undefined,
          createTime: undefined,
          lastupdateTime: undefined
        }

        this.resetForm('form')
      },
      cancel() {
        this.$emit('on-close')
        this.open = false
      }
    },
    created() {
      this.reset()
    }
  }
</script>
